package com.ethan.cj.ssm.controller;

import com.ethan.cj.ssm.entity.Logs;
import com.ethan.cj.ssm.service.LogsService;
import com.ethan.cj.ssm.util.PageBean;
import lombok.extern.log4j.Log4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.Map;

/**
 * 日志控制层
 */
@Controller
@Log4j
@RequestMapping("logs")
public class LogsController {
    /**
     * 日志service层映射
     */
    @Autowired
    private LogsService ls;

    /**
     * 进入分页页面
     * @return
     */
    @RequestMapping("list")
    public String list() {
        return "lw/logshome";
    }

    /**
     * 添加一条日志信息
     *
     * @param logs 日志对象
     */
    @RequestMapping("/insertLogs")
    @ResponseBody
    public void inserLogs(@RequestParam("logs") Logs logs) {
        ls.insertLogs(logs);
    }

    /**
     * 分页查询
     * @param page 页数
     * @param params 查询条件: 操作者
     * @return 前端字符串
     */
    @RequestMapping("/logsPage")
    @ResponseBody
    public Map<Object,Object> logsPage(
            @RequestParam("page") int page
            , @RequestParam("limit") int limit
            , @RequestParam(value = "params", required = false) String params
             ) {
        PageBean<Logs> pb = new PageBean<>(page,limit);
        return ls.selectLogs(pb ,params);
    }

    /**
     * 查询所有日志信息
     * @return 日志 json对象
     */
    @RequestMapping("/logsList")
    @ResponseBody
    public Map<Object,Object> logsList () {
        return ls.logsList();
    }
}
